<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  name: "SelectResources",
  props: {
    // 使用者window实例 必定义
    appWindow: {
      type: Object,
      default: null,
    },
    // 接口列表
    apiConfig: {
      type: Object,
      default: {
        // 分组添加 -------------
        albumAdd: {
          url: "mall-site-portal/album/create",
        },
        // 分组删除
        albumDel: {
          url: "mall-site-portal/album/delete",
        },
        // 分组编辑
        albumEdit: {
          url: "mall-site-portal/album/update",
        },

        // 数据列表 ---------------
        dataList: {
          url: "mall-site-portal/album-info/list",
        },
        // 数据删除
        dataDel: {
          url: "mall-site-portal/album-info/delete",
        },
        // 数据修改
        dataEdit: {
          url: "mall-site-portal/album-info/update",
        },
        // 数据同步
        dataSync: {
          url: "mall-site-portal/album-info/materialUpload",
        },

        // 素材分组 ---------------
        albumList: {
          url: "mall-site-portal/album/listAll",
        },
        // 素材配置
        fileConfig: {
          url: "mall-site-portal/album-info/getFileConfig",
        },
        // 素材创建
        createSubmit: {
          url: "mall-site-portal/album-info/createVideo",
        },
        // 文件上传
        fileUpload: {
          url: "mall-site-portal/oss-upload/upload",
        },
        // 封面上传
        imageUpload: {
          url: "mall-site-portal/oss-upload/uploadBase64",
        },
      },
    },
    cover: {
      type: String,
      default() {
        return "";
      },
    },
    video: {
      type: String,
      default() {
        return "";
      },
    },
    // 禁用
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  computed: {},
  data() {
    return {};
  },
  methods: {
    // 删除选择
    delSelectData() {
      if (this.disabled) {
        return;
      }
      this.updateValue("", "");
    },

    openBox() {
      if (this.disabled) {
        return;
      }
      this.$vFN.Directives.SelectResourcesVideo({
        appWindow: this.appWindow,
        apiConfig: this.apiConfig,
        count: 1,
        onSuccess: (res) => {
          this.updateValue(res.data[0].cover, res.data[0].video);
        },
      });
    },

    updateValue(cover, video) {
      this.$emit("update:video", video);
      this.$emit("update:cover", cover);
    },
  },
  watch: {},
  mounted() {},
  beforeCreate() {},
};
</script>